package LC0001;

import java.util.HashMap;
import java.util.Map;

public class LC13 {
    public int[] twoSum(int[] nums, int target) {
        Map<Integer,Integer> map=new HashMap<>();
        for(int i=0;i<nums.length;i++){
            int sub=target-nums[i];

            if(map.containsKey(sub)){
                return new int[]{i,map.get(sub)};
            }

            map.put(nums[i], i);    // TODO map是空的，怎么判断???
        }
        throw new IllegalArgumentException("No two sum solution");
    }

    public static void main(String[] args) {
        int[] a = {1,2,4,8,7,9};
        int target = 3;
        LC13 test = new LC13();
        int[] b = test.twoSum(a, target);
        for (int i: b){
            System.out.println(i);
        }

    }

}
